#include <iostream>
#include <stack>

using namespace std;
const int N = 1e5 + 10;

int main()
{
	int pushed[N], popped[N];
	int q; cin >> q;
	while (q--)
	{
		int n; cin >> n;
		for (int i = 1; i <= n; i++) cin >> pushed[i];
		for (int i = 1; i <= n; i++) cin >> popped[i];
		
		stack<int> st;
		int j = 1;
		for(int i = 1; i <= n; i++)
		{
			st.push(pushed[i]);
			while(j <= n && st.size() && st.top() == popped[j])
			{
				st.pop();
				j++;
			}
		}
		if (st.size()) cout << "No" << endl;
		else cout << "Yes" << endl;
	}

	return 0;
}

